package com.motorhome.api.controller;

import com.motorhome.api.service.DeviceService;
import com.motorhome.base.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: John
 */
@Controller
@RequestMapping(value = "/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @RequestMapping(value = "/getLocation", method = RequestMethod.POST)
    public @ResponseBody Result getLocation(HttpServletRequest request) {
        String deviceNumber = request.getParameter("deviceNumber");
        return deviceService.getLocation(deviceNumber);
    }

    @RequestMapping(value = "/getLocationOther", method = RequestMethod.POST)
    public @ResponseBody Result getLocationOther(HttpServletRequest request) {
        String deviceNumber = request.getParameter("deviceNumber");
        return deviceService.getLocationOther(deviceNumber);
    }

    @RequestMapping(value = "/getMapLocation", method = RequestMethod.POST)
    public @ResponseBody Result getMapLocation(HttpServletRequest request) {
        return deviceService.getMapLocation();
    }

    @RequestMapping(value = "/setOnOff", method = RequestMethod.POST)
    public @ResponseBody Result setOnOff(HttpServletRequest request) {
        String deviceNumber = request.getParameter("deviceNumber");
        String status = request.getParameter("status");
        return deviceService.setOnOff(deviceNumber, status);
    }

    @RequestMapping(value = "/getResList", method = RequestMethod.POST)
    public @ResponseBody Result getResList(HttpServletRequest request) {
        String deviceId = request.getParameter("deviceId");
        String page = request.getParameter("page");
        String pageSize = request.getParameter("pageSize");
        return deviceService.getResList(deviceId, page, pageSize);
    }

}
